<template>
	<div class="wrapper">
		<!-- 返回首页 -->
		<uni-bankhome />
		<div class="pay-wrapper">
			<div class="pay-money">
				{{paymentMethod=='WECHAT'?'￥':''}}{{ Number(payPrice) | unitPrice }}
			</div>
			<div class="pay-detail" v-if="origin==='order'">
				<div class="text" v-if="hbPrice!=0">商品价格：{{hbPrice}}</div>
				<div class="text" v-if="commission!=0">手续费：{{commission}}</div>
				<div class="text" v-if="freightPrice!=0">运费：{{freightPrice}}</div>
			</div>
			<div class="pay-btns">
				<div v-show="!from" @click="checkOrder">查看{{orderType == "RECHARGE" ? '余额' : '订单'}}</div>
				<div @click="navigateTo('/pages/tabbar/home/index', 'switch')">回到首页</div>
			</div>
		</div>
		<div class="pay-box">
			<div class="pay-tag-box">
				<h2>支付成功!</h2>
				<div class="pay-item">
					<div>
						支付方式：
					</div>
					<div>{{paymentMethod | paymentTypeFilter}}</div>
				</div>
			</div>
			<template v-if="rechargeType=='46'">
				<view class="goods-evaluate-view">
					<view class="goods-view">
						<text style="font-size: 18px;">评价</text>
					</view>
					<view>
						<u-rate count="count" gutter="20" active-color="#FFC71C" v-model="grade" :size="40">
						</u-rate>
					</view>
				</view>
				<u-button class='but' type="error" size="medium" @click='publishClick()'>发表</u-button>
			</template>
		</div>
		<!-- <goodsRecommend /> -->
	</div>

</template>
<script>
	import goodsRecommend from "@/components/m-goods-recommend";
	import {
		shopEvaluation
	} from "@/api/members.js";
	export default {
		data() {
			return {
				checked: false,
				paymentMethod: "",
				orderType: '',
				from: "",
				payPrice: 0,
				origin: '',
				hbPrice: 0,
				freightPrice: 0, // 运费
				successPrice: 0, // 焕贝支付一共需要的焕贝额
				commission: 0, // 手续费
				goodsList: [],
				activeColor: this.$mainColor,
				rechargeType: '',
				grade: 5, //评分
				orderSn: '', //商品单号
			};
		},
		components: {
			goodsRecommend,
		},
		filters: {
			paymentTypeFilter(val) {
				switch (val) {
					case "WECHAT":
						return "微信";
					case "ALIPAY":
						return "支付宝";
					case "WALLET":
						return "余额支付";
					default:
						return "";
				}
			},
		},
		onLoad(options) {
			console.log('options', options)
			this.paymentMethod = options.paymentMethod || "";
			this.from = options.from || "";
			this.payPrice = options.payPrice || 0;
			this.hbPrice = options.hbPrice || 0;
			this.origin = options.origin;
			this.commission = options.commission || 0;
			this.freightPrice = options.freightPrice || 0;
			this.orderType = options.orderType;
			this.rechargeType = options.rechargeType || ''
			this.orderSn = options.orderSn
			// this.sendMessage()
		},
		methods: {
			//发表评价
			publishClick() {
				shopEvaluation({
					storeScore: this.grade,
					orderNo: this.orderSn
				}).then((res) => {
					uni.hideLoading();
					if (res.data.success) {
						uni.showToast({
							title: "发布评价成功",
							duration: 2000,
							icon: "none",
							success: () => {
								setTimeout(() => {
									uni.switchTab({
										url: `/pages/tabbar/home/index`,
									});
								}, 500);
							},
						});
					}
				});
			},
			checkOrder() {
				/**
				 * 查看订单
				 * 1.充值跳转到明细里面
				 * 2.支付跳转到订单详情
				 */
				if (this.orderType == "RECHARGE") {
					uni.reLaunch({
						url: "/pages/mine/withdrawal/moneyhistory?type=" + 'RECHARGE',
					});
				} else {
					this.navigateTo("/pages/order/myOrder?status=0");
				}
			},
			changeStatus(val) {
				if (val) {
					this.sendMessage();
				}
			},

			navigateTo(url, type) {
				if (type === "switch") {
					uni.switchTab({
						url,
					});
				} else {
					uni.redirectTo({
						url,
					});
				}
			},
		},
	};
</script>
<style scoped lang="scss">
	.subscribe {
		justify-content: space-between;
		align-items: center;
		margin: 0 auto 40rpx auto;
		padding: 0 20rpx 20rpx;
		width: 80%;
	}

	.pay-btns {
		display: flex;
		width: 50%;
		justify-content: space-between;
		margin: 0 auto;
		color: #fff;
		margin-top: 32upx;

		>div {
			padding: 6px 12px;
			border: 1px solid #fff;
			border-radius: 100px;
		}
	}

	.pay-money {
		line-height: 1;
		font-size: 50rpx;
		color: #fff;
	}

	.pay-item {
		font-weight: bold;
		margin: 32rpx 0;
		display: flex;
		justify-content: space-between;
		font-size: 24rpx;
		color: rgba($color: $main-color, $alpha: 0.8);
	}

	.pay-box {
		overflow: hidden;
		padding-bottom: 20upx;
	}

	.pay-tag-box {
		width: 80%;
		margin: 80rpx auto 40rpx auto;
		padding: 20rpx;
		border-radius: 20rpx;
		background: rgba($color: $main-color, $alpha: 0.2);

		>h2 {
			margin-top: 20rpx;
			font-size: 40rpx;
			color: $main-color;
		}
	}

	.pay-wrapper {
		background-image: linear-gradient(90deg, #fa123b, #ff6b35, #ff9f28, #ffcc03);
		height: 600rpx;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		.pay-detail{
			display: flex;
			justify-content: center;
			margin: 24upx 0;
			.text{
				font-size: 28upx;
				margin: 0 12upx;
				color: #ffffff;
			}
		}
	}

	.pay-box {
		transform: translateY(-100rpx);
		width: 100%;
		background: #fff;
		border-top-right-radius: 100rpx;
	}

	.goods-evaluate-view {
		margin-top: 8rpx;
		padding: 20rpx;
		padding-left: 100rpx;
		margin-bottom: 50rpx;
		background-color: #fff;
		display: flex;
		flex-direction: row;
		align-items: center;

		.goods-view {
			width: 250rpx;
			font-size: 28rpx;
			color: #333333;


			.sub-title {
				font-size: 22rpx;
				color: #cccccc;
			}
		}
	}

	.but {
		margin-left: 256upx;
	}
</style>
